import { message, Modal } from 'antd'
import React, { useState } from 'react'

export default function useDelData(props: any) {
    const [ids, setIds] = useState([])
    const delData = (currentIds) => {
        Modal.confirm({
            title: props.title || '确认删除该数据吗？',
            onOk() {
                fetch(props.url, {
                    method: "POST",
                    body: JSON.stringify({ids:currentIds||ids}),
                    headers: {
                        "Content-Type": "application/json"
                    }
                }).then(res => res.json()).then(res => {
                    console.log(res)
                    message.success("删除成功");
                    props.success() && props.success()
                })
            }
        })
    }
    return {
        ids,
        setIds,
        delData
    }
}
